package com.xingfly.suan;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.xingfly.model.dto.Seat;
import com.xingfly.model.dto.User;

public class flightMan {

	/**
	 * 单人分配
	 */
	public static Map<String, Object> Allot(List<User> lus, List<Seat> seas, int serial) {
		Map<String, Object> map = new HashMap<>();
		List<Temp> tempData = new LinkedList<>();
		int count = 0, index, max = 0, reminx;
		float bcfpmyd = 0;
		Seat sea = null;
		String SeatType = null;
		String utstr = null;
		String[] ut = null;
		long startTime = System.currentTimeMillis();
		// 用户集合
		int ddcs = 0;
		for (User utmp : lus) {
			reminx = 0;
			index = -1;
			utstr = utmp.getPrefer();
			ut = utstr.split(",");
			// 座位集合
			for (Seat stmp : seas) {
				count = 0;
				SeatType = stmp.getSeatType();
				for (int i = 0; i < ut.length; i++) {
					if (SeatType.contains(ut[i]))
						count++;
				}
				// if(stmp.getSeid()==2||stmp.getSeid()==5)continue;
				if (utstr.length() == SeatType.length() && count == SeatType.split(",").length) {
					sea = stmp;
					max = count;
					break;
				}
				if (count > index) {
					sea = stmp;
					max = count;
					index = count;
				}
				reminx++;
				ddcs++;
			}

			Temp temp = new Temp(utmp.getUid(), sea.getSeid(), serial, (float) (max / (1.0 * ut.length)) * 100,
					utmp.getPrefer());
			tempData.add(temp);
		}
		long endTime = System.currentTimeMillis(); // 获取结束时间
		long sfhs = endTime - startTime;
		// 计算本次满意度
		for (Temp s : tempData) {
			bcfpmyd += s.getSatis();
		}
		bcfpmyd /= tempData.size();
		// 计算本次意度
		map.put("sfhs", sfhs);
		map.put("ddcs", ddcs);
		map.put("bcfpmyd", bcfpmyd);
		map.put("tempData", tempData);
		return map;
	}
	
	

}
